package com.whh.permission.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whh.permission.dao.IFileDao;
import com.whh.permission.po.File;
import com.whh.permission.service.IFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class FileServiceImpl implements IFileService {
    @Resource
    private IFileDao iFileDao;
    @Override
    public PageInfo<File> queryFile(int page,int pageSize,File file) {
        PageHelper.startPage(page,pageSize);
        List<File> files = iFileDao.queryFileAll(file);
        PageInfo<File> filePageInfo = new PageInfo<>(files);
        return filePageInfo;
    }

    @Override
    public void addFileInfo(File file) {
        //是否是图片解决方案:当类型中含有image时说明当前类型一定为图片类型
        String isImg = file.getType().startsWith("image") ? "是" : "否";
        file.setIsImg(isImg);
        file.setDowncounts(0);
        file.setUploadTime(new Date());
        iFileDao.addFileInfo(file);
    }

    @Override
    public void updateFile(File file) {
        iFileDao.updateFile(file);
    }

    @Override
    public File queryFileById(Integer id) {
        return iFileDao.queryFileById(id);
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        iFileDao.deleteByIds(ids);
    }
}
